package hv.fmw.utils {
	import flash.display.LoaderInfo;
	import flash.utils.Dictionary;

	/**
	 * @author hvong
	 */
	public class Config {
		
		private static var _flashvars : Dictionary = new Dictionary();
		private static var _paths : Dictionary = new Dictionary();
		private static var _path:String;

		public function Config() {
		}

		/*
		 * Save flashvars in a dictionary
		 */
		public static function init(info : LoaderInfo) : void {
			var fvObject:Object = info.parameters;
			for (var i:String in fvObject) {
				_flashvars[i] = fvObject[i];
			}
			
			_path = (new RegExp("file://").test(info.url)) ? "../" : "";
		}

		/*
		 * Save flashvars in a dictionary
		 */
		public static function configure(data:XML) : void {
			for each(var i:* in data.paths.path) {
				_paths[String(i.@id)] = _path + i;
			}
		}

		/*
		 * Get flashvars
		 */
		public static function getFlashVar(code : String) : String {
			return _flashvars[code];
		}

		/*
		 * Set flashvar
		 */
		public static function setPath(code : String, value:String) : void {
			_paths[code] = value;
		}

		/*
		 * Get path
		 */
		public static function getPath(code:String="") : String {
			var path:String = (code=="") ? _path : _paths[code];
			return path;
		}
	}
}
